package cn.elegent.txdemo.product.rollback;


import cn.elegent.tx.annotation.RollBack;
import cn.elegent.tx.context.Snapshot;
import cn.elegent.tx.core.rollback.RollBackHandler;
import cn.elegent.txdemo.common.dto.PayDto;
import cn.elegent.txdemo.product.service.ProductService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

@RollBack(mainName = "pay",childName = "product")
@Slf4j
public class ProductRollBackHandler implements RollBackHandler {

    @Autowired
    private ProductService productService;

    @Override
    public void doRollBack(String topic, Snapshot snapshot) {
        log.info("收到了回滚的消息来自："+topic+",数据："+snapshot.getData());
        PayDto payDto = snapshot.findData("payDto", PayDto.class);

        productService.payBack( payDto );

    }
}
